//封装http请求
import router from '../router'
import axios from "axios";
import Qs from "qs";
export default {
   http(url, param, success, failed) {
      var host = 'http://yitai.zhen-yee.com'
      // var host = 'http://192.168.50.222:8087'
      // var host = 'http://192.168.50.19:9090'
      var uuu = host + url
      var token = sessionStorage.getItem("token")
      if (param == null) {
         param = {
            'token': token,
            'app': 1
         }
      } else {
         param["token"] = token
         param["app"] = 1
      }
      // 用Qs转换字符类型
      const paramdata = Qs.stringify(param);

      axios({
            url: uuu,
            method: "post",
            data: paramdata,
            headers: {
               "Content-Type": "application/x-www-form-urlencoded"
            }
         })
         .then(function (response) {
            if (response.data.status == 401) { 
               router.push({ path: "/" }); 
            } else if(response.status == 200){
               success(response)
            } else {
               failed(response)
            }
         })
         .catch(function (error) {
            console.log(error);
         });
   }
}